
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DesignPatternDefinitions;
using System.Collections.Generic;

namespace BusinessLayer
{
	public class ApplicationDataSet : IDesignPatternSubject
	{
		#region fields
		private System.Data.DataTable ProjectTable;
		private System.Data.DataColumn ProjNameDataColumn;
		private System.Data.DataColumn ProjectAuthorDataColumn;
		private System.Data.DataColumn ProjectSummaryDataColumn;
		private System.Data.DataTable ComponentDataTable;
		private System.Data.DataColumn ComponentNameDataColumn;
		private System.Data.DataColumn ComponentAuthorDataColumn;
		private System.Data.DataColumn ComponentSummaryDataColumn;
		private System.Data.DataTable ClassDataTable;
		private System.Data.DataColumn CompNameDataColumn;
		private System.Data.DataColumn ClassNameDataColumn;
		private System.Data.DataColumn AccModDataColumn;
		private System.Data.DataColumn ClsSummaryDataColumn;
		private System.Data.DataTable MethodDataTable;
		private System.Data.DataColumn dataColumn1;
		private System.Data.DataColumn dataColumn2;
		private System.Data.DataColumn dataColumn3;
		private System.Data.DataColumn dataColumn4;
		private System.Data.DataColumn dataColumn5;
		private System.Data.DataTable FieldDataTable;
		private System.Data.DataTable ParameterDataTable;
		private System.Data.DataColumn dataColumn6;
		private System.Data.DataColumn dataColumn7;
		private System.Data.DataColumn dataColumn8;
		private System.Data.DataColumn dataColumn9;
		private System.Data.DataColumn dataColumn12;
		private System.Data.DataColumn dataColumn13;
		private System.Data.DataColumn dataColumn14;
		private System.Data.DataColumn dataColumn15;
		private System.Data.DataColumn dataColumn16;
		private System.Data.DataTable InheritanceDataTable;
		private System.Data.DataColumn dataColumn17;
		private System.Data.DataColumn dataColumn18;
		private System.Data.DataColumn dataColumn19;
		private System.Data.DataColumn dataColumn20;
		private System.Data.DataTable AggregatesDataTable;
		private System.Data.DataColumn dataColumn22;
		private System.Data.DataColumn dataColumn23;
		private System.Data.DataColumn dataColumn24;
		private System.Data.DataColumn dataColumn25;
		private System.Data.DataColumn dataColumn26;
		private System.Data.DataTable ReferencesDataTable;
		private System.Data.DataColumn dataColumn29;
		private System.Data.DataColumn dataColumn30;
		private System.Data.DataColumn dataColumn31;
		private System.Data.DataColumn dataColumn32;
		private System.Data.DataColumn dataColumn33;
		private System.Data.DataColumn dataColumn34;
		private System.Data.DataTable CreatesDataTable;
		private System.Data.DataColumn dataColumn36;
		private System.Data.DataColumn dataColumn37;
		private System.Data.DataColumn dataColumn38;
		private System.Data.DataColumn dataColumn39;
		private System.Data.DataColumn dataColumn40;
		protected internal System.Data.DataSet DPAppDataSet;
		private System.Data.DataColumn dataColumn43;
		private System.Data.DataColumn dataColumn44;
		private System.Data.DataColumn dataColumn45;
		private System.Data.DataColumn dataColumn28;
		private System.Data.DataColumn dataColumn47;
		private System.Data.DataColumn dataColumn10;
		private System.Data.DataColumn dataColumn11;
		private System.Data.DataColumn dataColumn42;
		private System.Data.DataTable dataTable1;
		private System.Data.DataColumn dataColumn46;
		private System.Data.DataColumn dataColumn48;
		private System.Data.DataColumn dataColumn49;
		private System.Data.DataColumn dataColumn50;
		private System.Data.DataColumn dataColumn51;
		private System.Data.DataColumn dataColumn52;
		private System.Data.DataColumn dataColumn53;
		private System.Data.DataColumn dataColumn54;
		private System.Data.DataTable dataTable2;
		private System.Data.DataColumn dataColumn55;
		private System.Data.DataColumn dataColumn56;
		private System.Data.DataTable dataTable3;
		private System.Data.DataColumn dataColumn21;
		private System.Data.DataColumn dataColumn27;
		private System.Data.DataColumn dataColumn35;
		#endregion

		
		#region eventHashTable
		IDictionary<string, ClassEventContainer> eventTable = new Dictionary<string, ClassEventContainer>();
		#endregion

		
		private bool autoCorrect=false;

		public ApplicationDataSet()
		{
			InitializeTables();
		}

		#region Table creation
		private void InitializeTables()
		{
			this.DPAppDataSet = new System.Data.DataSet();
			this.ProjectTable = new System.Data.DataTable();
			this.ProjNameDataColumn = new System.Data.DataColumn();
			this.ProjectAuthorDataColumn = new System.Data.DataColumn();
			this.ProjectSummaryDataColumn = new System.Data.DataColumn();
			this.ComponentDataTable = new System.Data.DataTable();
			this.ComponentNameDataColumn = new System.Data.DataColumn();
			this.ComponentAuthorDataColumn = new System.Data.DataColumn();
			this.ComponentSummaryDataColumn = new System.Data.DataColumn();
			this.ClassDataTable = new System.Data.DataTable();
			this.CompNameDataColumn = new System.Data.DataColumn();
			this.ClassNameDataColumn = new System.Data.DataColumn();
			this.AccModDataColumn = new System.Data.DataColumn();
			this.ClsSummaryDataColumn = new System.Data.DataColumn();
			this.dataColumn43 = new System.Data.DataColumn();
			this.dataColumn44 = new System.Data.DataColumn();
			this.dataColumn51 = new System.Data.DataColumn();
			this.MethodDataTable = new System.Data.DataTable();
			this.dataColumn1 = new System.Data.DataColumn();
			this.dataColumn2 = new System.Data.DataColumn();
			this.dataColumn3 = new System.Data.DataColumn();
			this.dataColumn4 = new System.Data.DataColumn();
			this.dataColumn5 = new System.Data.DataColumn();
			this.dataColumn45 = new System.Data.DataColumn();
			this.dataColumn28 = new System.Data.DataColumn();
			this.dataColumn47 = new System.Data.DataColumn();
			this.dataColumn52 = new System.Data.DataColumn();
			this.FieldDataTable = new System.Data.DataTable();
			this.dataColumn6 = new System.Data.DataColumn();
			this.dataColumn7 = new System.Data.DataColumn();
			this.dataColumn8 = new System.Data.DataColumn();
			this.dataColumn9 = new System.Data.DataColumn();
			this.dataColumn14 = new System.Data.DataColumn();
			this.dataColumn16 = new System.Data.DataColumn();
			this.dataColumn53 = new System.Data.DataColumn();
			this.ParameterDataTable = new System.Data.DataTable();
			this.dataColumn12 = new System.Data.DataColumn();
			this.dataColumn13 = new System.Data.DataColumn();
			this.dataColumn15 = new System.Data.DataColumn();
			this.dataColumn10 = new System.Data.DataColumn();
			this.dataColumn11 = new System.Data.DataColumn();
			this.dataColumn54 = new System.Data.DataColumn();
			this.InheritanceDataTable = new System.Data.DataTable();
			this.dataColumn17 = new System.Data.DataColumn();
			this.dataColumn18 = new System.Data.DataColumn();
			this.dataColumn19 = new System.Data.DataColumn();
			this.dataColumn20 = new System.Data.DataColumn();
			this.AggregatesDataTable = new System.Data.DataTable();
			this.dataColumn22 = new System.Data.DataColumn();
			this.dataColumn23 = new System.Data.DataColumn();
			this.dataColumn24 = new System.Data.DataColumn();
			this.dataColumn25 = new System.Data.DataColumn();
			this.dataColumn26 = new System.Data.DataColumn();
			this.dataColumn42 = new System.Data.DataColumn();
			this.ReferencesDataTable = new System.Data.DataTable();
			this.dataColumn29 = new System.Data.DataColumn();
			this.dataColumn30 = new System.Data.DataColumn();
			this.dataColumn31 = new System.Data.DataColumn();
			this.dataColumn32 = new System.Data.DataColumn();
			this.dataColumn33 = new System.Data.DataColumn();
			this.dataColumn34 = new System.Data.DataColumn();
			this.CreatesDataTable = new System.Data.DataTable();
			this.dataColumn36 = new System.Data.DataColumn();
			this.dataColumn37 = new System.Data.DataColumn();
			this.dataColumn38 = new System.Data.DataColumn();
			this.dataColumn39 = new System.Data.DataColumn();
			this.dataColumn40 = new System.Data.DataColumn();
			this.dataTable1 = new System.Data.DataTable();
			this.dataColumn46 = new System.Data.DataColumn();
			this.dataColumn48 = new System.Data.DataColumn();
			this.dataColumn49 = new System.Data.DataColumn();
			this.dataColumn50 = new System.Data.DataColumn();
			this.dataTable2 = new System.Data.DataTable();
			this.dataColumn55 = new System.Data.DataColumn();
			this.dataColumn56 = new System.Data.DataColumn();
			this.dataTable3 = new System.Data.DataTable();
			this.dataColumn21 = new System.Data.DataColumn();
			this.dataColumn27 = new System.Data.DataColumn();
			this.dataColumn35 = new System.Data.DataColumn();
			((System.ComponentModel.ISupportInitialize)(this.DPAppDataSet)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ProjectTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ComponentDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ClassDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.MethodDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.FieldDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ParameterDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.InheritanceDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.AggregatesDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ReferencesDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.CreatesDataTable)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable3)).BeginInit();
			// 
			// DPAppDataSet
			// 
			this.DPAppDataSet.CaseSensitive = true;
			this.DPAppDataSet.DataSetName = "DesignPatternProject";
			this.DPAppDataSet.Locale = new System.Globalization.CultureInfo("en-US");
			this.DPAppDataSet.Tables.AddRange(new System.Data.DataTable[] {
											      this.ProjectTable,
											      this.ComponentDataTable,
											      this.ClassDataTable,
											      this.MethodDataTable,
											      this.FieldDataTable,
											      this.ParameterDataTable,
											      this.InheritanceDataTable,
											      this.AggregatesDataTable,
											      this.ReferencesDataTable,
											      this.CreatesDataTable,
											      this.dataTable1,
											      this.dataTable2,
											      this.dataTable3});
			// 
			// ProjectTable
			// 
			this.ProjectTable.Columns.AddRange(new System.Data.DataColumn[] {
												this.ProjNameDataColumn,
												this.ProjectAuthorDataColumn,
												this.ProjectSummaryDataColumn});
			this.ProjectTable.Constraints.AddRange(new System.Data.Constraint[] {
												    new System.Data.UniqueConstraint("Constraint1", new string[] {
																					 "ProjectName"}, true)});
			this.ProjectTable.PrimaryKey = new System.Data.DataColumn[] {
											    this.ProjNameDataColumn};
			this.ProjectTable.TableName = "Project";
			// 
			// ProjNameDataColumn
			// 
			this.ProjNameDataColumn.AllowDBNull = false;
			this.ProjNameDataColumn.ColumnName = "ProjectName";
			// 
			// ProjectAuthorDataColumn
			// 
			this.ProjectAuthorDataColumn.ColumnName = "ProjectAuthor";
			// 
			// ProjectSummaryDataColumn
			// 
			this.ProjectSummaryDataColumn.ColumnName = "Summary";
			// 
			// ComponentDataTable
			// 
			this.ComponentDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												      this.ComponentNameDataColumn,
												      this.ComponentAuthorDataColumn,
												      this.ComponentSummaryDataColumn});
			this.ComponentDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													  new System.Data.UniqueConstraint("Constraint1", new string[] {
																					       "ComponentName"}, true)});
			this.ComponentDataTable.PrimaryKey = new System.Data.DataColumn[] {
												  this.ComponentNameDataColumn};
			this.ComponentDataTable.TableName = "Components";
			// 
			// ComponentNameDataColumn
			// 
			this.ComponentNameDataColumn.AllowDBNull = false;
			this.ComponentNameDataColumn.ColumnName = "ComponentName";
			// 
			// ComponentAuthorDataColumn
			// 
			this.ComponentAuthorDataColumn.ColumnName = "ComponentAuthor";
			// 
			// ComponentSummaryDataColumn
			// 
			this.ComponentSummaryDataColumn.ColumnName = "Summary";
			// 
			// ClassDataTable
			// 
			this.ClassDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												  this.CompNameDataColumn,
												  this.ClassNameDataColumn,
												  this.AccModDataColumn,
												  this.ClsSummaryDataColumn,
												  this.dataColumn43,
												  this.dataColumn44,
												  this.dataColumn51});
			this.ClassDataTable.Constraints.AddRange(new System.Data.Constraint[] {
												      new System.Data.UniqueConstraint("Constraint1", new string[] {
																					   "ComponentName",
																					   "ClassName"}, true),
												      new System.Data.ForeignKeyConstraint("ForeignConstraint1", "Components", new string[] {
																								    "ComponentName"}, new string[] {
																													   "ComponentName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.ClassDataTable.PrimaryKey = new System.Data.DataColumn[] {
											      this.CompNameDataColumn,
											      this.ClassNameDataColumn};
			this.ClassDataTable.TableName = "Classes";
			// 
			// CompNameDataColumn
			// 
			this.CompNameDataColumn.AllowDBNull = false;
			this.CompNameDataColumn.ColumnName = "ComponentName";
			// 
			// ClassNameDataColumn
			// 
			this.ClassNameDataColumn.AllowDBNull = false;
			this.ClassNameDataColumn.ColumnName = "ClassName";
			// 
			// AccModDataColumn
			// 
			this.AccModDataColumn.ColumnName = "Visibility";
			// 
			// ClsSummaryDataColumn
			// 
			this.ClsSummaryDataColumn.ColumnName = "Summary";
			// 
			// dataColumn43
			// 
			this.dataColumn43.ColumnName = "ClassType";
			// 
			// dataColumn44
			// 
			this.dataColumn44.ColumnName = "AssociatedPattern";
			// 
			// dataColumn51
			// 
			this.dataColumn51.ColumnName = "MetaInfo";
			this.dataColumn51.DefaultValue = "";
			// 
			// MethodDataTable
			// 
			this.MethodDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												   this.dataColumn1,
												   this.dataColumn2,
												   this.dataColumn3,
												   this.dataColumn4,
												   this.dataColumn5,
												   this.dataColumn45,
												   this.dataColumn28,
												   this.dataColumn47,
												   this.dataColumn52});
			this.MethodDataTable.Constraints.AddRange(new System.Data.Constraint[] {
												       new System.Data.ForeignKeyConstraint("FKConstraint", "Classes", new string[] {
																							    "ComponentName",
																							    "ClassName"}, new string[] {
																											       "ComponentName",
																											       "ClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.MethodDataTable.TableName = "Methods";
			// 
			// dataColumn1
			// 
			this.dataColumn1.ColumnName = "ComponentName";
			// 
			// dataColumn2
			// 
			this.dataColumn2.ColumnName = "ClassName";
			// 
			// dataColumn3
			// 
			this.dataColumn3.AllowDBNull = false;
			this.dataColumn3.ColumnName = "MethodName";
			// 
			// dataColumn4
			// 
			this.dataColumn4.AllowDBNull = false;
			this.dataColumn4.ColumnName = "Visibility";
			// 
			// dataColumn5
			// 
			this.dataColumn5.ColumnName = "Summary";
			// 
			// dataColumn45
			// 
			this.dataColumn45.AllowDBNull = false;
			this.dataColumn45.ColumnName = "ReturnType";
			// 
			// dataColumn28
			// 
			this.dataColumn28.AllowDBNull = false;
			this.dataColumn28.ColumnName = "MethodType";
			// 
			// dataColumn47
			// 
			this.dataColumn47.AllowDBNull = false;
			this.dataColumn47.ColumnName = "MethodID";
			this.dataColumn47.DataType = typeof(int);
			// 
			// dataColumn52
			// 
			this.dataColumn52.ColumnName = "MetaInfo";
			this.dataColumn52.DefaultValue = "";
			// 
			// FieldDataTable
			// 
			this.FieldDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												  this.dataColumn6,
												  this.dataColumn7,
												  this.dataColumn8,
												  this.dataColumn9,
												  this.dataColumn14,
												  this.dataColumn16,
												  this.dataColumn53});
			this.FieldDataTable.Constraints.AddRange(new System.Data.Constraint[] {
												      new System.Data.UniqueConstraint("Constraint1", new string[] {
																					   "ComponentName",
																					   "ClassName",
																					   "FieldName"}, true),
												      new System.Data.ForeignKeyConstraint("FieldFKConstraint", "Classes", new string[] {
																								"ComponentName",
																								"ClassName"}, new string[] {
																												   "ComponentName",
																												   "ClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.FieldDataTable.PrimaryKey = new System.Data.DataColumn[] {
											      this.dataColumn6,
											      this.dataColumn7,
											      this.dataColumn9};
			this.FieldDataTable.TableName = "Fields";
			// 
			// dataColumn6
			// 
			this.dataColumn6.AllowDBNull = false;
			this.dataColumn6.ColumnName = "ComponentName";
			this.dataColumn6.DefaultValue = "";
			// 
			// dataColumn7
			// 
			this.dataColumn7.AllowDBNull = false;
			this.dataColumn7.ColumnName = "ClassName";
			// 
			// dataColumn8
			// 
			this.dataColumn8.ColumnName = "FieldType";
			// 
			// dataColumn9
			// 
			this.dataColumn9.AllowDBNull = false;
			this.dataColumn9.ColumnName = "FieldName";
			// 
			// dataColumn14
			// 
			this.dataColumn14.ColumnName = "Summary";
			// 
			// dataColumn16
			// 
			this.dataColumn16.ColumnName = "Visibility";
			// 
			// dataColumn53
			// 
			this.dataColumn53.ColumnName = "MetaInfo";
			this.dataColumn53.DefaultValue = "";
			// 
			// ParameterDataTable
			// 
			this.ParameterDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												      this.dataColumn12,
												      this.dataColumn13,
												      this.dataColumn15,
												      this.dataColumn10,
												      this.dataColumn11,
												      this.dataColumn54});
			this.ParameterDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													  new System.Data.UniqueConstraint("Constraint1", new string[] {
																					       "MethodID",
																					       "ParameterName"}, true)});
			this.ParameterDataTable.PrimaryKey = new System.Data.DataColumn[] {
												  this.dataColumn10,
												  this.dataColumn13};
			this.ParameterDataTable.TableName = "Parameters";
			// 
			// dataColumn12
			// 
			this.dataColumn12.ColumnName = "ParameterType";
			this.dataColumn12.DefaultValue = "";
			// 
			// dataColumn13
			// 
			this.dataColumn13.AllowDBNull = false;
			this.dataColumn13.ColumnName = "ParameterName";
			// 
			// dataColumn15
			// 
			this.dataColumn15.ColumnName = "Summary";
			// 
			// dataColumn10
			// 
			this.dataColumn10.AllowDBNull = false;
			this.dataColumn10.ColumnName = "MethodID";
			this.dataColumn10.DataType = typeof(int);
			// 
			// dataColumn11
			// 
			this.dataColumn11.ColumnName = "ParamOrder";
			this.dataColumn11.DataType = typeof(int);
			// 
			// dataColumn54
			// 
			this.dataColumn54.ColumnName = "MetaInfo";
			this.dataColumn54.DefaultValue = "";
			// 
			// InheritanceDataTable
			// 
			this.InheritanceDataTable.Columns.AddRange(new System.Data.DataColumn[] {
													this.dataColumn17,
													this.dataColumn18,
													this.dataColumn19,
													this.dataColumn20});
			this.InheritanceDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													    new System.Data.UniqueConstraint("Constraint1", new string[] {
																						 "BaseClassComponent",
																						 "BaseClassName",
																						 "DerivedClassComponent",
																						 "DerivedClassName"}, true),
													    new System.Data.ForeignKeyConstraint("Constraint2", "Classes", new string[] {
																								"ComponentName",
																								"ClassName"}, new string[] {
																												   "BaseClassComponent",
																												   "BaseClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade),
													    new System.Data.ForeignKeyConstraint("Constraint3", "Classes", new string[] {
																								"ComponentName",
																								"ClassName"}, new string[] {
																												   "DerivedClassComponent",
																												   "DerivedClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.InheritanceDataTable.PrimaryKey = new System.Data.DataColumn[] {
												    this.dataColumn17,
												    this.dataColumn18,
												    this.dataColumn19,
												    this.dataColumn20};
			this.InheritanceDataTable.TableName = "Inheritances";
			// 
			// dataColumn17
			// 
			this.dataColumn17.AllowDBNull = false;
			this.dataColumn17.ColumnName = "BaseClassComponent";
			// 
			// dataColumn18
			// 
			this.dataColumn18.AllowDBNull = false;
			this.dataColumn18.ColumnName = "BaseClassName";
			// 
			// dataColumn19
			// 
			this.dataColumn19.AllowDBNull = false;
			this.dataColumn19.Caption = "DerivedClassComponent";
			this.dataColumn19.ColumnName = "DerivedClassComponent";
			// 
			// dataColumn20
			// 
			this.dataColumn20.AllowDBNull = false;
			this.dataColumn20.ColumnName = "DerivedClassName";
			// 
			// AggregatesDataTable
			// 
			this.AggregatesDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												       this.dataColumn22,
												       this.dataColumn23,
												       this.dataColumn24,
												       this.dataColumn25,
												       this.dataColumn26,
												       this.dataColumn42});
			this.AggregatesDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													   new System.Data.UniqueConstraint("Constraint1", new string[] {
																						"AggregatorClassComponent",
																						"AggregatorClass",
																						"AggregateeClassComponent",
																						"AggregateeClass",
																						"RelationName"}, true),
													   new System.Data.ForeignKeyConstraint("Constraint3", "Classes", new string[] {
																							       "ComponentName",
																							       "ClassName"}, new string[] {
																												  "AggregateeClassComponent",
																												  "AggregateeClass"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade),
													   new System.Data.ForeignKeyConstraint("Constraint2", "Classes", new string[] {
																							       "ComponentName",
																							       "ClassName"}, new string[] {
																												  "AggregatorClassComponent",
																												  "AggregatorClass"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.AggregatesDataTable.PrimaryKey = new System.Data.DataColumn[] {
												   this.dataColumn22,
												   this.dataColumn23,
												   this.dataColumn24,
												   this.dataColumn25,
												   this.dataColumn42};
			this.AggregatesDataTable.TableName = "Aggregates";
			// 
			// dataColumn22
			// 
			this.dataColumn22.AllowDBNull = false;
			this.dataColumn22.ColumnName = "AggregatorClassComponent";
			// 
			// dataColumn23
			// 
			this.dataColumn23.AllowDBNull = false;
			this.dataColumn23.ColumnName = "AggregatorClass";
			// 
			// dataColumn24
			// 
			this.dataColumn24.AllowDBNull = false;
			this.dataColumn24.ColumnName = "AggregateeClassComponent";
			// 
			// dataColumn25
			// 
			this.dataColumn25.AllowDBNull = false;
			this.dataColumn25.ColumnName = "AggregateeClass";
			// 
			// dataColumn26
			// 
			this.dataColumn26.ColumnName = "RelationOrder";
			// 
			// dataColumn42
			// 
			this.dataColumn42.AllowDBNull = false;
			this.dataColumn42.ColumnName = "RelationName";
			// 
			// ReferencesDataTable
			// 
			this.ReferencesDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												       this.dataColumn29,
												       this.dataColumn30,
												       this.dataColumn31,
												       this.dataColumn32,
												       this.dataColumn33,
												       this.dataColumn34});
			this.ReferencesDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													   new System.Data.UniqueConstraint("Constraint1", new string[] {
																						"ReferenceComponent",
																						"ReferenceClass",
																						"ReferedComponentName",
																						"ReferedClassName",
																						"ReferenceName"}, true),
													   new System.Data.ForeignKeyConstraint("Constraint2", "Classes", new string[] {
																							       "ComponentName",
																							       "ClassName"}, new string[] {
																												  "ReferenceComponent",
																												  "ReferenceClass"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade),
													   new System.Data.ForeignKeyConstraint("Constraint3", "Classes", new string[] {
																							       "ComponentName",
																							       "ClassName"}, new string[] {
																												  "ReferedComponentName",
																												  "ReferedClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.ReferencesDataTable.PrimaryKey = new System.Data.DataColumn[] {
												   this.dataColumn29,
												   this.dataColumn30,
												   this.dataColumn31,
												   this.dataColumn32,
												   this.dataColumn33};
			this.ReferencesDataTable.TableName = "References";
			// 
			// dataColumn29
			// 
			this.dataColumn29.AllowDBNull = false;
			this.dataColumn29.ColumnName = "ReferenceComponent";
			// 
			// dataColumn30
			// 
			this.dataColumn30.AllowDBNull = false;
			this.dataColumn30.ColumnName = "ReferenceClass";
			// 
			// dataColumn31
			// 
			this.dataColumn31.AllowDBNull = false;
			this.dataColumn31.ColumnName = "ReferedComponentName";
			// 
			// dataColumn32
			// 
			this.dataColumn32.AllowDBNull = false;
			this.dataColumn32.ColumnName = "ReferedClassName";
			// 
			// dataColumn33
			// 
			this.dataColumn33.AllowDBNull = false;
			this.dataColumn33.ColumnName = "ReferenceName";
			// 
			// dataColumn34
			// 
			this.dataColumn34.ColumnName = "RelationOrder";
			// 
			// CreatesDataTable
			// 
			this.CreatesDataTable.Columns.AddRange(new System.Data.DataColumn[] {
												    this.dataColumn36,
												    this.dataColumn37,
												    this.dataColumn38,
												    this.dataColumn39,
												    this.dataColumn40});
			this.CreatesDataTable.Constraints.AddRange(new System.Data.Constraint[] {
													new System.Data.UniqueConstraint("Constraint1", new string[] {
																					     "CreatorComponentName",
																					     "CreatorClassName",
																					     "CreateeComponentName",
																					     "CreateeClassName"}, true),
													new System.Data.ForeignKeyConstraint("Constraint2", "Classes", new string[] {
																							    "ComponentName",
																							    "ClassName"}, new string[] {
																											       "CreatorComponentName",
																											       "CreatorClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade),
													new System.Data.ForeignKeyConstraint("Constraint3", "Classes", new string[] {
																							    "ComponentName",
																							    "ClassName"}, new string[] {
																											       "CreateeComponentName",
																											       "CreateeClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.CreatesDataTable.PrimaryKey = new System.Data.DataColumn[] {
												this.dataColumn36,
												this.dataColumn37,
												this.dataColumn38,
												this.dataColumn39};
			this.CreatesDataTable.TableName = "Creates";
			// 
			// dataColumn36
			// 
			this.dataColumn36.AllowDBNull = false;
			this.dataColumn36.ColumnName = "CreatorComponentName";
			// 
			// dataColumn37
			// 
			this.dataColumn37.AllowDBNull = false;
			this.dataColumn37.ColumnName = "CreatorClassName";
			// 
			// dataColumn38
			// 
			this.dataColumn38.AllowDBNull = false;
			this.dataColumn38.ColumnName = "CreateeComponentName";
			// 
			// dataColumn39
			// 
			this.dataColumn39.AllowDBNull = false;
			this.dataColumn39.ColumnName = "CreateeClassName";
			// 
			// dataColumn40
			// 
			this.dataColumn40.ColumnName = "RelationOrder";
			// 
			// dataTable1
			// 
			this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {
											      this.dataColumn46,
											      this.dataColumn48,
											      this.dataColumn49,
											      this.dataColumn50});
			this.dataTable1.Constraints.AddRange(new System.Data.Constraint[] {
												  new System.Data.ForeignKeyConstraint("Constraint1", "Classes", new string[] {
																						      "ComponentName",
																						      "ClassName"}, new string[] {
																											 "ComponentName",
																											 "ClassName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
			this.dataTable1.TableName = "UIDetails";
			// 
			// dataColumn46
			// 
			this.dataColumn46.AllowDBNull = false;
			this.dataColumn46.ColumnName = "ComponentName";
			// 
			// dataColumn48
			// 
			this.dataColumn48.AllowDBNull = false;
			this.dataColumn48.ColumnName = "ClassName";
			// 
			// dataColumn49
			// 
			this.dataColumn49.ColumnName = "XCoOrdinate";
			this.dataColumn49.DataType = typeof(int);
			// 
			// dataColumn50
			// 
			this.dataColumn50.ColumnName = "YCoOrdinate";
			this.dataColumn50.DataType = typeof(int);
			// 
			// dataTable2
			// 
			this.dataTable2.Columns.AddRange(new System.Data.DataColumn[] {
											      this.dataColumn55,
											      this.dataColumn56});
			this.dataTable2.Constraints.AddRange(new System.Data.Constraint[] {
												  new System.Data.UniqueConstraint("Constraint1", new string[] {
																				       "Detail"}, true)});
			this.dataTable2.PrimaryKey = new System.Data.DataColumn[] {
											  this.dataColumn55};
			this.dataTable2.TableName = "Misc";
			// 
			// dataColumn55
			// 
			this.dataColumn55.AllowDBNull = false;
			this.dataColumn55.ColumnName = "Detail";
			this.dataColumn55.DefaultValue = "";
			// 
			// dataColumn56
			// 
			this.dataColumn56.ColumnName = "Info";
			this.dataColumn56.DefaultValue = "";
			// 
			// dataTable3
			// 
			this.dataTable3.Columns.AddRange(new System.Data.DataColumn[] {
											      this.dataColumn21,
											      this.dataColumn27,
											      this.dataColumn35});
			this.dataTable3.Constraints.AddRange(new System.Data.Constraint[] {
												  new System.Data.ForeignKeyConstraint("Constraint1", "Components", new string[] {
																							 "ComponentName"}, new string[] {
																												"ComponentName"}, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade),
												  new System.Data.UniqueConstraint("Constraint2", new string[] {
																				       "ComponentName"}, true)});
			this.dataTable3.PrimaryKey = new System.Data.DataColumn[] {
											  this.dataColumn21};
			this.dataTable3.TableName = "ComponentUIDetails";
			// 
			// dataColumn21
			// 
			this.dataColumn21.AllowDBNull = false;
			this.dataColumn21.ColumnName = "ComponentName";
			// 
			// dataColumn27
			// 
			this.dataColumn27.ColumnName = "Width";
			this.dataColumn27.DataType = typeof(int);
			// 
			// dataColumn35
			// 
			this.dataColumn35.ColumnName = "Height";
			this.dataColumn35.DataType = typeof(int);
			
			((System.ComponentModel.ISupportInitialize)(this.DPAppDataSet)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ProjectTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ComponentDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ClassDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.MethodDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.FieldDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ParameterDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.InheritanceDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.AggregatesDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ReferencesDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.CreatesDataTable)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataTable3)).EndInit();

		}
		#endregion

		private void CheckForNullColumns( DataRow row)
		{
			//if(!silent) ErrorMessage.Show("Checking for null cols for table"+ row.Table.TableName,"Info");
			for (int i=0;i<row.Table.Columns.Count;++i)
			{
				if(row[i]== null)
				{
					Console.WriteLine("Found a null for col:"+ row.Table.Columns[i].ColumnName,"Null found");
					row[i]=string.Empty;
				}
				else{}
					//if(!silent) ErrorMessage.Show("row["+i+"]="+row[i],"Info");
			}
		}
		#region IDesignPatternSubject Members
		
		#region Project and Component related functions
		public bool CreateNewProject(IProject proj)
		{
			
			DataRow nRow = DPAppDataSet.Tables[SchemaNames.Project].NewRow();
					
			nRow[SchemaNames.ProjectName]=proj.ProjectName;
			nRow[SchemaNames.ProjectAuthor]=proj.ProjectAuthor;
			nRow[SchemaNames.Summary]=proj.ProjectSummary;
			this.CheckForNullColumns(nRow);
			try
			{
				DPAppDataSet.Tables[SchemaNames.Project].Rows.Add(nRow);
			}
			catch ( ConstraintException )
			{
				if(!silent) ErrorMessage.Show(proj.ProjectName + " project already present","Duplicate Project Name");
				return false;
			}
			
			if ( proj.Components!=null && proj.Components.Count>0)
				foreach( IProjectComponent projComp in proj.Components)
					this.CreateNewComponent( projComp);
			return true;
		}
		public IProject ProjectDetails{
			get{return new DPProject(this.DPAppDataSet); }
			set
			{
				IProject proj = value as IProject;
				DataTable projTable = this.DPAppDataSet.Tables[SchemaNames.Project];
				if (projTable.Rows.Count==0)
				{
					this.CreateNewProject(proj);
					return;
				}
				DataRow projRow = (projTable).Rows[0];
				projRow[SchemaNames.ProjectName]=proj.ProjectName;
				projRow[SchemaNames.ProjectAuthor]=proj.ProjectAuthor;
				projRow[SchemaNames.Summary]=proj.ProjectSummary;
			}
		}

		public bool CreateNewComponent(IProjectComponent comp)
		{

			DataRow nRow = DPAppDataSet.Tables[SchemaNames.Components].NewRow();
			
			nRow[SchemaNames.ComponentName]=comp.ComponentName;
			nRow[SchemaNames.ComponentAuthor]=comp.ComponentAuthor;
			nRow[SchemaNames.Summary]=comp.ComponentSummary;
			this.CheckForNullColumns(nRow);
			try
			{
				DPAppDataSet.Tables[SchemaNames.Components].Rows.Add(nRow);
			}
			catch ( ConstraintException )
			{
				if(!silent) ErrorMessage.Show(comp.ComponentName + " component already present in project:"+this.ProjectDetails.ProjectName,"Duplicate Component Name");
				return false;
			}
			
			if( comp.Classes==null || comp.Classes.Count==0)
				return true;
			else 
				foreach( IClass cls in comp.Classes)
					this.AddClass(cls);

			return true;
		}

		public bool ContainsComponent(string comp)
		{
			DataTable comptable =  DPAppDataSet.Tables[SchemaNames.Components];
			return comptable.Rows.Contains(comp);
		}
		public bool DeleteComponent(string compName)
		{
			//first delete the entry in event container
			this.eventTable.Remove(compName);
			DataTable table = this.DPAppDataSet.Tables[SchemaNames.Components];
			DataRow row = table.Rows.Find(compName);
			table.Rows.Remove(row);
			return true;
		}
		public bool UpdateComponentDetails(IProjectComponent oldComp, IProjectComponent newComp)
		{
			
			DataTable comptable =  DPAppDataSet.Tables[SchemaNames.Components];
            string oldComponentName = oldComp.ComponentName;
            DataRow row = comptable.Rows.Find(oldComp.ComponentName);

			row[SchemaNames.ComponentAuthor]=newComp.ComponentAuthor;
			row[SchemaNames.Summary]=newComp.ComponentSummary;

            if (oldComponentName != newComp.ComponentName)
			{
				try
				{
                    //ClassEventContainer cec;
					row[SchemaNames.ComponentName]=newComp.ComponentName;
                    this.eventTable.Add(newComp.ComponentName,
                        this.eventTable[oldComponentName]
                        );

                    this.eventTable.Remove(oldComponentName);
					this.UpdateComponents();
					return true;
				}
				catch(Exception exp)
				{
					MessageBox.Show(exp.ToString());
					return false;
				}

			}
			
			
			return true;
			
			
		}
		
		public void AddComponentUIDetails(string compName,int width,int height)
		{
			
			DataTable table = this.DataSet.Tables[SchemaNames.ComponentUIDetails];
			DataRow row = table.Rows.Find(compName);
			
			if( row ==null)
			{
				row=table.NewRow();
				row[SchemaNames.ComponentName]=compName;
				row[SchemaNames.Width]=width;
				row[SchemaNames.Height]=height;
				table.Rows.Add(row);
			}
			
			row[SchemaNames.ComponentName]=compName;
			row[SchemaNames.Width]=width;
			row[SchemaNames.Height]=height;
		}
		#endregion
		
		#region Class related functions
		public bool AddClass(IClass cls)
		{
			DataTable ctable = this.DPAppDataSet.Tables[SchemaNames.Classes];
			if( ctable.Rows.Find(new object[]{ cls.ComponentName,
								 cls.ClassName}) !=null )
			{
				if(!silent) ErrorMessage.Show("Class already present","Duplicate class");
				return false;
			}
			if( this.autoCorrect )
			{
				//create the component if it doesnot exist.
				
				DataTable compTable = this.DPAppDataSet.Tables[SchemaNames.Components];
				if( compTable.Rows.Find( cls.ComponentName )== null )
				{
					Console.WriteLine("AutoCorrecting....Creating a component that doesnot exist::"+cls.ComponentName );
					IProjectComponent comp=new InfoClasses.ProjectComponentInfo ();
					comp.ComponentName=cls.ComponentName;
					comp.ComponentAuthor="AutoCreated";
					comp.ComponentSummary="AutoCreated";
					this.CreateNewComponent( comp);
				}
			}
			//create the row
			DataRow nrow = ctable.NewRow();
			nrow[SchemaNames.ComponentName]=cls.ComponentName;
			nrow[SchemaNames.ClassName]=cls.ClassName;
			nrow[SchemaNames.Visibility]= cls.AccessModifier;
			if ( cls.Abstract )
				nrow[SchemaNames.ClassType]=ClassType.Abstract.ToString().ToLower();
			else
				nrow[SchemaNames.ClassType]=ClassType.Concrete.ToString().ToLower();
			nrow[SchemaNames.Summary]=cls.ClassSummary;
			this.CheckForNullColumns(nrow);
			Hashtable metainfo = cls.GetAllMetaInfo();
			MetaInfoEditor mie = new MetaInfoEditor(metainfo);
			nrow[SchemaNames.MetaInfo]=mie.MetaInfo;
			ctable.Rows.Add(nrow);

			if(cls.UILocation.X>0 && cls.UILocation.Y>0)//if u find the uilocation add it or the uilocation will self created in the UIClass.
			{
				this.AddClassUIDetails(cls.ComponentName,cls.ClassName,cls.UILocation);
				
			}
			
			//now create the fields and methods.
			ArrayList methods= cls.Methods;
			ArrayList fields = cls.Fields;

			if( methods!= null && methods.Count>0)
				foreach ( IMethod mthd in methods )
					this.AddMethod(cls.ComponentName,cls.ClassName,mthd);
			Console.WriteLine("Now checking for fields.....");
			if (fields!=null && fields.Count >0)
				foreach (IField fld in fields)
					this.AddField(cls.ComponentName,cls.ClassName,fld);

			
			return true;
		}

		public bool RenameClass(string component,string oldname,string newname)
		{
			if (this.ContainsClass(component,newname) )
				return false;
			DataRow row = this.DPAppDataSet.Tables [SchemaNames.Classes].Rows.Find( new object[]{ component,oldname} );
			if( row!=null)
			{
				row[SchemaNames.ClassName]=newname;
				return true;
			}
			return false;

		}
		public bool ContainsClass(string comp,string cname)
		{
			DataRow row = this.DPAppDataSet.Tables [SchemaNames.Classes].Rows.Find( new object[]{ comp,cname} );
			if( row != null)
				return true;
			return false;
		}

		public void DeleteClass(string comp,string cname)
		{
			if (
				MessageBox.Show("Delete the class "+ cname + " , along with the assoicated relations?\n If this class is imported by other components, the remote class will be deleted from the respective components","Delete Class",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
				== DialogResult.No
				)
				return;
			DataTable table = this.DPAppDataSet.Tables[SchemaNames.Classes];
			DataRow row = table.Rows.Find(new object[]
				{
					comp,cname
				}
				);
			if ( row == null)
			{
				if(!silent) ErrorMessage.Show("Error while deleting, Class details not found in the in-memory cache","Error");
				return;
			}
			table.Rows.Remove( row);
//			ClassEventContainer cec = eventTable[comp] as ClassEventContainer;
//			cec.EmitReInitialize();
//			this.UpdateComponent(comp);
			this.UpdateComponents();

		}

		#endregion
		
		#region Fields and Methods
		public bool AddField(string componentName,string className , IField fld)
		{
				Console.WriteLine("Adding Field {0},{1}",fld.FieldName,fld.FieldType);
			DataTable table = this.DPAppDataSet.Tables[SchemaNames.Fields];
			DataRow row = table.NewRow();
			row[SchemaNames.ComponentName]=componentName;
			row[SchemaNames.ClassName]=className;
			row[SchemaNames.FieldType]=fld.FieldType;
			row[SchemaNames.FieldName]=fld.FieldName;
			row[SchemaNames.Visibility]=fld.FieldVisibility;
			row[SchemaNames.Summary]=fld.FieldSummary;
			Hashtable metaInfoMap = fld.GetAllMetaInfo();
			MetaInfoEditor mie = new MetaInfoEditor(metaInfoMap);
			row[SchemaNames.MetaInfo]=mie.MetaInfo;
			this.CheckForNullColumns(row);
			try
			{
				table.Rows.Add(row);
				Console.WriteLine("Field row added");
			}
			catch (ConstraintException)
			{
				if(!silent) ErrorMessage.Show("Field Already present!","Duplicate field found");
				return false;
			}
			return true;
		}
		public bool RemoveField ( string componentName,string className, IField fld)
		{
			return false;
		}

		public bool AddMethod( string componentName,string className,IMethod mthd)
		{
			
			DataTable mtable = this.DPAppDataSet.Tables[SchemaNames.Methods];
			DataRow row = mtable.NewRow();

			row[SchemaNames.ComponentName]=componentName;
			row[SchemaNames.ClassName]=className;
			row[SchemaNames.MethodName]=mthd.MethodName;
			row[SchemaNames.MethodReturnType]=mthd.MethodReturnType;
			row[SchemaNames.MethodType]=mthd.MethodType.ToString().ToLower();
			row[SchemaNames.Visibility]=mthd.MethodVisibility;
			row[SchemaNames.Summary]=mthd.MethodSummary;
			Hashtable metaInfoMap = mthd.GetAllMetaInfo();
			MetaInfoEditor mie = new MetaInfoEditor(metaInfoMap);
			row[SchemaNames.MetaInfo]=mie.MetaInfo;
			this.CheckForNullColumns(row);
			//generate the hash value for the method...
			//to avoid the same hash value from being generated if the methods are 
			//overloaded ...use the current date time
			string hashstr = componentName+":"+className+":"+mthd.MethodName+":"+DateTime.Now.ToString()+DateTime.UtcNow.ToString();
			object mid = hashstr.GetHashCode();
			row[SchemaNames.MethodID]= mid;	
			try
			{
				mtable.Rows.Add(row);
				
			}
			catch (ConstraintException exp)
			{
				MessageBox.Show(exp.ToString());
				return false;
			}

			if( mthd.Parameters!=null && mthd.Parameters.Count>0)
				foreach( IParameter param in mthd.Parameters)
					this.AddParameter(mid,param);

			return true;
		}
		public bool RemoveMethod ( string componentName,string className,IMethod mthd)
		{
			return false;
		}
		
		
		public bool AddParameter( object uniqueMethodId, IParameter param)
		{
			int mid = (int)uniqueMethodId;
			
			DataTable table = this.DPAppDataSet.Tables[SchemaNames.Parameters];
			DataRow row = table.NewRow();

			try
			{
				//before setting the parameter order , find the order.
				DataRow [] prows = this.DPAppDataSet.Tables[SchemaNames.Parameters].Select(SchemaNames.MethodID+"='"+mid+"'");
				row[SchemaNames.MethodID]=mid;
				row[SchemaNames.ParameterName]=param.ParameterName;
				row[SchemaNames.ParameterType]=param.ParameterType;
				row[SchemaNames.Summary]=param.Summary;
				row[SchemaNames.ParamOrder]=prows.Length;
				Hashtable metaInfoMap = param.GetAllMetaInfo();
				MetaInfoEditor mie = new MetaInfoEditor(metaInfoMap);
				row[SchemaNames.MetaInfo]=mie.MetaInfo;
				
				this.CheckForNullColumns(row);
				table.Rows.Add(row);
			}
			catch (ConstraintException)
			{
				//MessageBox.Show(exp.ToString());
				//if(!silent) ErrorMessage.Show("Parameter Already present!","Duplicate parameter found");
				return false;
			}
			return true;
		}
		#endregion
		
		#region Inheritance
		public bool  AddInheritance( IInheritance inh, bool addBaseClassMembers)
		{
			if( inh.BaseClass==inh.DerivedClass)
			{
				if(!silent) ErrorMessage.Show("Base class and Derived Class cannot be same","Error");
				return false;
			}
			
			//check for cyclic references
			DataTable inhTable = this.DPAppDataSet.Tables[SchemaNames.Inheritances];
			DataRow[] rows = inhTable.Select(SchemaNames.BaseClassComponent+"='"+inh.DerivedClassComponent+
					"' and "+
				SchemaNames.DerivedClassComponent+"='"+inh.BaseClassComponent+"' and " +
				SchemaNames.BaseClass+"='"+inh.DerivedClass+"' and " +
				SchemaNames.DerivedClass+"='"+inh.BaseClass+"'");
			if(rows.Length!=0)
			{
				if(!silent) ErrorMessage.Show("Cyclic inheritances are not allowed!" ,"Error!");
				return false;
			}
			DataRow nrow =inhTable.NewRow();
			try
			{
				if( this.autoCorrect)
				this.CheckAndCreate(inh.BaseClassComponent,inh.BaseClass);
				nrow[SchemaNames.BaseClassComponent]=inh.BaseClassComponent;
				nrow[SchemaNames.BaseClass]=inh.BaseClass;
				nrow[SchemaNames.DerivedClassComponent]=inh.DerivedClassComponent;
				nrow[SchemaNames.DerivedClass]=inh.DerivedClass;
				inhTable.Rows.Add(nrow);
			}
			catch(ConstraintException)
			{
				if(!silent) ErrorMessage.Show("The inheritance already exists!","error");
				return false;
			}
			//Now add the methods+fields of the base class into the derived class.
			bool methodAdded = false; //indicator for method addition..used for emiting the signal.
			bool fieldAdded = false ; // same for fields..
			if(addBaseClassMembers)
			{
				Hashtable htable = new Hashtable(); //used to find duplicate methods and fileds.
				IProject proj = this.GetProject();
				IClass baseClass = proj.GetClass(inh.BaseClassComponent,inh.BaseClass);
				IClass derClass = proj.GetClass(inh.DerivedClassComponent,inh.DerivedClass);
				foreach(IMethod mthd in derClass.Methods)
				{
					if(!htable.Contains(mthd.UMLRepresentation))
						htable.Add(mthd.UMLRepresentation,0);
				}
				foreach(IMethod mthd in baseClass.Methods)
				{
					if(!htable.Contains(mthd.UMLRepresentation) && 
						mthd.MethodVisibility.ToLower() != "private")
					{
						methodAdded = true;
						/* backup the orifinal method type and summary */
						MethodType oldMethodType = mthd.MethodType;
						string oldSummary = mthd.MethodSummary;
						mthd.MethodType = MethodType.Concrete;
						mthd.MethodSummary=string.Empty;
						mthd.MethodSummary = "[Inherited from Base Class : "+baseClass.ClassName 
								+ " of Component:"+baseClass.ComponentName+"]";
						this.AddMethod(derClass.ComponentName,
							derClass.ClassName,mthd);
						mthd.MethodSummary = oldSummary;
						mthd.MethodType = oldMethodType;
					}
				}
				htable.Clear();
				foreach(IField fld in derClass.Fields)
				{
					if(!htable.Contains(fld.UMLRepresentation))
						htable.Add(fld.UMLRepresentation,0);
				}
				foreach(IField fld in baseClass.Fields)
				{
					if(!htable.Contains(fld.UMLRepresentation) &&
						fld.FieldVisibility.ToLower() != "private")
					{
						fieldAdded = true;
						string oldFldSummary = fld.FieldSummary;
						fld.FieldSummary=string.Empty;
						fld.FieldSummary = "[Inherited from Base Class : "+
							baseClass.ClassName + " of Component:"+
							baseClass.ComponentName+"]";
						this.AddField(inh.DerivedClassComponent,inh.DerivedClass,fld);
						fld.FieldSummary = oldFldSummary;

					}
				}
				
			}

			if( this.autouiUpdate)
			{
				ClassEventContainer cec = eventTable[inh.DerivedClassComponent];
				if(cec!=null)
				{
					cec.EmitClassRelationsUpdated(inh.DerivedClass, 
						new DPClass(inh.DerivedClassComponent,
						inh.DerivedClass,
						this.DPAppDataSet)
						);
					if(methodAdded)
					{
						cec.EmitClassMethodsUpdated(inh.DerivedClass,
							new DPClass(inh.DerivedClassComponent,
							inh.DerivedClass,
							this.DPAppDataSet)
							);
					}
					if(fieldAdded)
					{
						cec.EmitClassFieldsUpdated(inh.DerivedClass,
							new DPClass(inh.DerivedClassComponent,
							inh.DerivedClass,
							this.DPAppDataSet)
							);
					}
				}

			}
			return true;
		}

		public bool RemoveInheritance( IInheritance inh)
		{
			DataTable inhTable = this.DPAppDataSet.Tables[SchemaNames.Inheritances];
			DataRow row = GetInhRow(inh);
			if(row==null)
				return false;
			inhTable.Rows.Remove(row);
			this.UpdateComponent(inh.DerivedClassComponent);
			return true;
		}
		private DataRow GetInhRow(IInheritance inh)
		{
			DataTable inhTable = this.DPAppDataSet.Tables[SchemaNames.Inheritances];
			DataRow[] rows = inhTable.Select(
				SchemaNames.BaseClassComponent+"='"+inh.BaseClassComponent+
				"' and "+
				SchemaNames.DerivedClassComponent+"='"+inh.DerivedClassComponent+"' and " +
				SchemaNames.BaseClass+"='"+inh.BaseClass+"' and " +
				SchemaNames.DerivedClass+"='"+inh.DerivedClass+"'");
			if(rows.Length!=1)
				return null;
			return rows[0];
		}

		#endregion

		#region Reference
		private DataRow GetReferenceRow(IReference _ref)
		{
			DataTable refTable = this.DPAppDataSet.Tables[SchemaNames.References];
			DataRow[] rows = refTable.Select(
				SchemaNames.ReferedClassName+"='"+_ref.ReferedClassName+ "' and "+
				SchemaNames.ReferedComponentName+"='"+_ref.ReferedComponentName+"' and " +
				SchemaNames.ReferenceClass+"='"+_ref.ReferenceClass+"' and " +
				SchemaNames.ReferenceComponent+"='"+_ref.ReferenceComponent+"' and " +
				SchemaNames.ReferenceName+"='"+_ref.ReferenceName+"' and " +
				SchemaNames.RelationOrder+"='"+_ref.Order.ToString()+"'"
				);
			if(rows == null || rows.Length != 1)
				return null;
			return rows[0];

		}
		public bool AddReference( IReference rf)
		{
			DataTable creTable = this.DPAppDataSet.Tables[SchemaNames.References];
			DataRow[] rows = creTable.Select(SchemaNames.ReferedComponentName+"='"+rf.ReferenceComponent+
				"' and "+
				SchemaNames.ReferenceComponent+"='"+rf.ReferedComponentName+
				"' and " +
				SchemaNames.ReferenceClass+"='"+rf.ReferedClassName+ 
				"' and " +
				SchemaNames.ReferedClassName+"='"+rf.ReferenceClass+"'");
			if(rows.Length!=0)
			{
				if(!silent) ErrorMessage.Show("Cyclic refrences are not allowed!" ,"Error!");
				return false;
			}

			DataRow nrow =creTable.NewRow();
				
			try
			{
				if( this.autoCorrect)
				this.CheckAndCreate(rf.ReferedComponentName,rf.ReferedClassName);
				nrow[SchemaNames.ReferenceComponent]=rf.ReferenceComponent;
				nrow[SchemaNames.ReferenceClass]=rf.ReferenceClass;
				nrow[SchemaNames.ReferedComponentName]=rf.ReferedComponentName;
				nrow[SchemaNames.ReferedClassName]=rf.ReferedClassName;
				nrow[SchemaNames.ReferenceName]=rf.ReferenceName;
				nrow[SchemaNames.RelationOrder]=rf.Order.ToString();
				creTable.Rows.Add(nrow);
			}
			catch(ConstraintException)
			{
				if(!silent) ErrorMessage.Show("The reference "+ rf.ReferenceName+"  already exists!","error");
				return false;
			}

			Console.WriteLine("Getting the event container for:"+rf.ReferenceComponent);
			
			if( this.autouiUpdate)
			{
				ClassEventContainer cec = eventTable[rf.ReferenceComponent];
				if(cec!=null)
					cec.EmitClassRelationsUpdated(rf.ReferenceClass,
						new DPClass(rf.ReferenceComponent,
						rf.ReferenceClass,
						this.DPAppDataSet));
			}
			return true;
		}
		
		public bool RemoveReference( IReference _ref)
		{
			DataTable refTable = this.DPAppDataSet.Tables[SchemaNames.References];
			DataRow refRow = this.GetReferenceRow(_ref);
			if(refRow == null)
				return false;
			refTable.Rows.Remove(refRow);
			this.UpdateComponent(_ref.ReferenceComponent);
			return true;
		}
		public bool UpdateReference( IReference oldRef, IReference newRef)
		{
			try
			{
			DataTable refTable = this.DPAppDataSet.Tables[SchemaNames.References];
			DataRow refRow = this.GetReferenceRow(oldRef);
			
				refRow[SchemaNames.ReferedClassName]     = newRef.ReferedClassName;
				refRow[SchemaNames.ReferedComponentName] = newRef.ReferedComponentName;
				refRow[SchemaNames.ReferenceClass]       = newRef.ReferenceClass;
				refRow[SchemaNames.ReferenceComponent]   = newRef.ReferenceComponent;
				refRow[SchemaNames.ReferenceName]         = newRef.ReferenceName;
				refRow[SchemaNames.RelationOrder]        = newRef.Order.ToString();
				this.UpdateComponent(newRef.ReferenceComponent);
				if(oldRef.ReferenceComponent != newRef.ReferenceComponent)
				{
					this.UpdateComponent(oldRef.ReferedComponentName);
				}
				return true;
			}
			catch(Exception exp)
			{
				ErrorMessage.Show("Following error occured during updating Reference:\n"
					+ exp.Message );
				return false;
			}

		}

		#endregion

		#region Aggregate
		private DataRow GetAggregateRow(IAggregate agg)
		{
			DataTable aggTable = this.DPAppDataSet.Tables[SchemaNames.Aggregates];
			DataRow[] rows = aggTable.Select(
				SchemaNames.AggregateeClassComponent+"='"+agg.AggregateeClassComponent+ "' and "+
				SchemaNames.AggregatorClassComponent+"='"+agg.AggregatorClassComponent+	"' and " +
				SchemaNames.AggregatorClass+"='"+agg.AggregatorClass+"' and " +
				SchemaNames.AggregateeClass+"='"+agg.AggregateeClass+"' and " +
				SchemaNames.RelationName+"='"+agg.AggregateName+"' and " +
				SchemaNames.RelationOrder+"='"+agg.Order.ToString()+"'"
				);
			if(rows == null || rows.Length != 1)
				return null;
			return rows[0];

		}
		public bool AddAggregate( IAggregate agg)
		{
			DataTable creTable = this.DPAppDataSet.Tables[SchemaNames.Aggregates];
			DataRow[] rows = creTable.Select(SchemaNames.AggregatorClassComponent+"='"+agg.AggregateeClassComponent+
				"' and "+
				SchemaNames.AggregateeClassComponent+"='"+agg.AggregatorClassComponent+
				"' and " +
				SchemaNames.AggregatorClass+"='"+agg.AggregateeClass+"' and " +
				SchemaNames.AggregateeClass+"='"+agg.AggregatorClass+"'");
			if(rows.Length!=0)
			{
				if(!silent) ErrorMessage.Show("Cyclic aggregates are not allowed!" ,"Error!");
				return false;
			}

			DataRow nrow =creTable.NewRow();
			
			try
			{
				if( this.autoCorrect)
					this.CheckAndCreate(agg.AggregateeClassComponent,
						agg.AggregateeClass);
				nrow[SchemaNames.AggregateeClassComponent]=agg.AggregateeClassComponent;
				nrow[SchemaNames.AggregateeClass]=agg.AggregateeClass;
				nrow[SchemaNames.AggregatorClassComponent]=agg.AggregatorClassComponent;
				nrow[SchemaNames.AggregatorClass]=agg.AggregatorClass;
				nrow[SchemaNames.RelationName]=agg.AggregateName;
				nrow[SchemaNames.RelationOrder]=agg.Order.ToString();
				creTable.Rows.Add(nrow);
			}
			catch(ConstraintException)
			{
				if(!silent) ErrorMessage.Show("The Aggregate with this name "+ agg.AggregateName +" already exists!","error");
				return false;
			}
			if( this.autouiUpdate)
			{
				ClassEventContainer cec = eventTable[agg.AggregatorClassComponent] as ClassEventContainer;
				if(cec!=null)
					cec.EmitClassRelationsUpdated(agg.AggregatorClass,
						new DPClass(agg.AggregatorClassComponent,
						agg.AggregatorClass,
						this.DPAppDataSet));
			}
			return true;
		}
		
		public bool RemoveAggregate( IAggregate agg)
		{
			DataTable aggTable = this.DPAppDataSet.Tables[SchemaNames.Aggregates];
			DataRow row = this.GetAggregateRow(agg);
			if(row==null)
				return false;
			aggTable.Rows.Remove(row);
			this.UpdateComponent(agg.AggregatorClassComponent);
			return true;


		}

		public bool UpdateAggregate(IAggregate oldAgg, IAggregate newAgg)
		{
			try
			{
				DataRow aggRow = this.GetAggregateRow(oldAgg);
				if(aggRow == null)
					return false;
				aggRow[SchemaNames.RelationName]=newAgg.AggregateName;
				aggRow[SchemaNames.AggregateeClass]=newAgg.AggregateeClass;
				aggRow[SchemaNames.AggregatorClass]=newAgg.AggregatorClass;
				aggRow[SchemaNames.AggregateeClassComponent]=newAgg.AggregateeClassComponent;
				aggRow[SchemaNames.AggregatorClassComponent]=newAgg.AggregatorClassComponent;
				aggRow[SchemaNames.RelationOrder]=newAgg.Order.ToString();
				this.UpdateComponent(newAgg.AggregatorClassComponent);
				if(oldAgg.AggregatorClassComponent != newAgg.AggregatorClassComponent)
				{
					this.UpdateComponent(oldAgg.AggregatorClassComponent);
				}
				return true;
			}
			catch(Exception exp)
			{
				ErrorMessage.Show("Following error occured during updating Aggregate:\n"
					+ exp.Message );
				return false;
			}
		}
		#endregion

		#region Creates
		private DataRow GetCreationRow(ICreation cr)
		{
			DataTable crTable = this.DPAppDataSet.Tables[SchemaNames.Creates];
			DataRow[] rows = crTable.Select(
				SchemaNames.CreatorComponentName+"='"+cr.CreatorComponentName+
				"' and " +
				SchemaNames.CreateeComponentName+"='"+cr.CreateeComponentName+"' and " +
				SchemaNames.CreateeClassName+"='"+cr.CreateeClassName+"' and " +
				SchemaNames.CreatorClassName+"='"+cr.CreatorClassName+"' and " +
				SchemaNames.RelationOrder+"='"+cr.Order+"'"
				);
			if(rows == null || rows.Length != 1)
				return null;
			return rows[0];
		}
		public bool AddCreates( ICreation cr)
		{
			DataTable creTable = this.DPAppDataSet.Tables[SchemaNames.Creates];
			DataRow[] rows = creTable.Select(SchemaNames.CreateeComponentName+"='"+cr.CreatorComponentName+
				"' and " +
				SchemaNames.CreatorComponentName+"='"+cr.CreateeComponentName+"' and " +
				SchemaNames.CreatorClassName+"='"+cr.CreateeClassName+"' and " +
				SchemaNames.CreateeClassName+"='"+cr.CreatorClassName+"'");
			if(rows.Length!=0)
			{
				if(!silent) ErrorMessage.Show("Cyclic creations are not allowed!" ,"Error!");
				return false;
			}

			DataRow nrow =creTable.NewRow();

			try
			{
				if( this.autoCorrect)
					this.CheckAndCreate(cr.CreateeComponentName,
						cr.CreateeClassName);
				nrow[SchemaNames.CreatorComponentName]=cr.CreatorComponentName;
				nrow[SchemaNames.CreatorClassName]=cr.CreatorClassName;
				nrow[SchemaNames.CreateeComponentName]=cr.CreateeComponentName;
				nrow[SchemaNames.CreateeClassName]=cr.CreateeClassName;
				nrow[SchemaNames.RelationOrder]=cr.Order.ToString();
				creTable.Rows.Add(nrow);
			}
			catch(ConstraintException)
			{
				if(!silent) ErrorMessage.Show("The creation relation already exists!\n Only one creates relation can exist between any 2 classes","error");
				return false;
			}
			if(this.autouiUpdate)
			{
				ClassEventContainer cec = eventTable[cr.CreatorComponentName] as ClassEventContainer;
				if(cec!=null)
					cec.EmitClassRelationsUpdated(cr.CreatorClassName,
						new DPClass(cr.CreatorComponentName,
						cr.CreatorClassName,
						this.DPAppDataSet));
			}
			return true;
		}

		public bool RemoveCreates( ICreation creates)
		{
			try
			{
				DataTable crTable = this.DPAppDataSet.Tables[SchemaNames.Creates];
				DataRow row = this.GetCreationRow(creates);
				if(row==null)
					return false;
				crTable.Rows.Remove(row);
				this.UpdateComponent(creates.CreatorComponentName);
				return true;
			}
			catch(Exception exp)
			{
				ErrorMessage.Show("Following error occured during deleting creates relation:\n"
					+ exp.Message );
				return false;
			}
		}
		public bool UpdateCreates(ICreation oldCr , ICreation newCr)
		{
			try
			{
				DataTable crTable = this.DPAppDataSet.Tables[SchemaNames.Creates];
				DataRow row = this.GetCreationRow(oldCr);
				if(row==null)
					return false;
				row[SchemaNames.CreatorComponentName] = newCr.CreatorComponentName;
				row[SchemaNames.CreateeComponentName] = newCr.CreateeComponentName;
				row[SchemaNames.CreateeClassName] = newCr.CreateeClassName;
				row[SchemaNames.CreatorClassName] = newCr.CreatorClassName;
				row[SchemaNames.RelationOrder] = newCr.Order;
				this.UpdateComponent(newCr.CreatorComponentName);
				if(newCr.CreatorComponentName != oldCr.CreateeComponentName)
					this.UpdateComponent(newCr.CreateeComponentName);
				return true;
			}
			catch(Exception exp)
			{
				ErrorMessage.Show("Following error occured during updating creates relation:\n"
					+ exp.Message );
				return false;

			}
		}

		#endregion
		
		public void Merge( string curcomp, string filename)
		{
			PluginDataStructure ds = new PluginDataStructure();
			OpenFileDialog dialog = new OpenFileDialog();
			
			if(filename == null)
				filename = string.Empty;
			
			string newFileName = filename;

			if(!System.IO.File.Exists(filename))
			{
				dialog.InitialDirectory=dpatoolkit.GlobalSettings.SampleDPPluginPath;
				if ( dialog.ShowDialog()== DialogResult.Cancel)
					return;
				dialog.Title="Open Plugin for merging";
				newFileName = dialog.FileName;
			}
			ds.ReadProject(newFileName );
			if( !ds.IsPattern() )
			{
				if(!silent) ErrorMessage.Show("This is not a valid plugin ..Merge failure","error");
				return;
			}

			DataSet dpdataset = ds.DataSet;
			DataTable table =  dpdataset.Tables[SchemaNames.Components];
			DataRow row = table.Rows.Find( PluginEditorForm.pluginTag);
			if(row==null)
			{
				if(!silent) ErrorMessage.Show("plugin Component not found","error");
				return;
			}
			// Display the details of the Design-Plugin.
			IDesignPatternSubject me = this;
			PlugInDetailsForm pidf = new PlugInDetailsForm(ds,this,curcomp);
			pidf.GenerateInfo(ds.DataSet.Tables[SchemaNames.Misc]);
			pidf.Closed+=new EventHandler(FinishMerge);
			pidf.Show();
			return;
		}

		#region WriteProject
		public bool WriteProject()
		{
			SaveFileDialog dialog = new SaveFileDialog();
			if ( dialog.ShowDialog()== DialogResult.Cancel)
				return false;
			return this.WriteProject(dialog.FileName);
		}
		
		public bool WriteProject(string fname)
		{
			
			foreach ( DataTable table in this.DPAppDataSet.Tables)
				foreach( DataColumn col in table.Columns)
					col.ColumnMapping=MappingType.Element;
			try
			{
				this.DPAppDataSet.WriteXml(fname,XmlWriteMode.IgnoreSchema);
				
			}
			
			catch( Exception e)
			{
				if(!silent) ErrorMessage.Show("Couldnot save, the following error was encountered:"+e.Message,"Error");
				return false;
			}
			return true;
		}
		#endregion

		#region ReadProject
		public bool ReadProject()
		{
			OpenFileDialog dialog = new OpenFileDialog();
				if ( dialog.ShowDialog()== DialogResult.Cancel)
					return false;
				string fname = dialog.FileName;
				return this.ReadProject(fname);
			
		}
		public bool ReadProject(string fname)
		{
			
			// now clear all the info;
			this.eventTable.Clear();
			this.DPAppDataSet.Clear();
			try
			{
				this.DPAppDataSet.ReadXml(fname,XmlReadMode.Auto);
			}
			catch( Exception exp)
			{
				if(!silent) ErrorMessage.Show("Couldnot open, The input is not a valid xml file!\n"+exp.Message,"Error");
				return false;
			}
			if(this.DPAppDataSet.HasErrors)
			{
				if(!silent) ErrorMessage.Show("The Data that was read back has errors! please check if the file is of correct format","error");
				return false;
			}
			return true;
			
			
		}

		#endregion

		public void ShowClassEditor( string comp , string cname,object specificVal)
		{
			try
			{
				string cname_old = cname;
				string cname_bup = cname;
				ClassDetailsEditForm form = new ClassDetailsEditForm(this.DPAppDataSet,comp,cname_bup,(int)specificVal ,this);;
				bool dupMethodExists = false;
				do
				{
					dupMethodExists = false;
					form = new ClassDetailsEditForm(this.DPAppDataSet,comp,cname_bup,(int)specificVal ,this);
					form.ShowDialog();
				
					DPClass checkCls = new DPClass(comp,form.ClassName,this.DPAppDataSet);
					Hashtable lookup = new Hashtable();
					lookup.Clear();
					foreach (IMethod mthd in checkCls.Methods)
					{
						if(!lookup.Contains(mthd.UMLRepresentation) )
							lookup.Add(mthd.UMLRepresentation,new object());
						else
						{
							ErrorMessage.Show("Duplicate Methods found , The method is: "+mthd.UMLRepresentation+ "\nTwo or more methods with same signature have been found, Please Edit." ,"Please check..");
							dupMethodExists = true;
							break;
						}
					}
					cname_bup = form.ClassName;
					specificVal=3;/*Index of the method section in the editor */
				}while(dupMethodExists);
				/* Update all components */
				this.UpdateComponents();
//				foreach ( ClassEventContainer clsEvntCtr in this.eventTable.Values)
//				{
//					DPClass dpcls = new DPClass(comp,form.ClassName,this.DPAppDataSet);
//					//Just in case if class name has been changed!
//					clsEvntCtr.EmitClassNameUpdated(cname_old,dpcls);
//					
//					cname = form.ClassName;
//                    
//					clsEvntCtr.EmitClassMethodsUpdated(cname,dpcls);
//				
//					clsEvntCtr.EmitClassFieldsUpdated(cname, dpcls);
//
//					clsEvntCtr.EmitClassRelationsUpdated(cname,dpcls);
//				}
			}
			catch (Exception exp)
			{
				if(!silent) ErrorMessage.Show("An Exception occcured! Please Report this bug \n Exception is message is: \n  " + exp.ToString(), "Error");
			}

		}
		
	
			
		public void RegisterDelegates(string compName , 
			AddNewClassObserver anco,
			ClassNameObserver cno, 
			ClassFieldObserver cfo , ClassMethodObserver cmo, 
			RelationObserver relObs,
			ReInitialize rein)
		{
		
			ClassEventContainer evntClass = new ClassEventContainer();
			evntClass.NewClassAdded+=anco;
			evntClass.ClassNameChanged+=cno;
			evntClass.ClassMethodsUpdated+=cmo;
			evntClass.ClassFieldsUpdated+=cfo;
			evntClass.ClassRelationsUpdated+=relObs;
			evntClass.ReInit+=rein;

            this.eventTable[compName] = evntClass;
		}

		public void AddClassUIDetails( string compName , string cName , Point p)
		{
			DataTable uitable = this.DPAppDataSet.Tables[SchemaNames.UIDetails];
			DataRow row;
			DataRow []arow = uitable.Select(SchemaNames.ComponentName+"='"+compName+"' and " +
				SchemaNames.ClassName+"='"+ cName+"'"	);
			
			if( arow.Length!=1)
			row = uitable.NewRow();
			else row = arow[0];
			try
			{
				row[SchemaNames.ComponentName]=compName;
				row[SchemaNames.ClassName]=cName;
				row[SchemaNames.XCoOrdinate]=p.X;
				row[SchemaNames.YCoOrdinate]=p.Y;
				if(arow.Length!=1)//a new row was created :)
					uitable.Rows.Add(row);
			}
			catch ( ConstraintException)
			{
				if(!silent) ErrorMessage.Show("Error while updating the uidetails!","Error");
			}
		}

		public void UpdateComponents()
		{
			
			//foreach component find the classes then emit the signal
			IProject proj =this.GetProject();
			foreach ( IProjectComponent comp in proj.Components)
			{
				//get the event handler class
				ClassEventContainer cec = eventTable[comp.ComponentName];
				if( cec==null)
				{
					if(!silent) ErrorMessage.Show("BUG! ClassEventContainer contains null for:"+comp.ComponentName,"Internal DataStructure Error");
					continue;
				}
				cec.EmitReInitialize();
				foreach ( IClass cls in comp.Classes)
					cec.EmitNewClassAdded(cls);
			
			}
			//now after creating the UIClass objects update the relaitons
			foreach ( IProjectComponent comp in proj.Components)
			{
				//get the event handler class 
				ClassEventContainer cec = eventTable[comp.ComponentName];
				foreach ( IClass cls in comp.Classes)
				{
					cec.EmitClassRelationsUpdated(cls.ClassName,cls);
				}
			}
			return;
		}
		public void UpdateComponent( string compName )
		{
			
			IProjectComponent comp = new DPComponent(this.DataSet.Tables[SchemaNames.Components].Rows.Find
				( compName));
			//update the classes
			ClassEventContainer cec = eventTable[comp.ComponentName];
			cec.EmitReInitialize();
			foreach ( IClass cls in comp.Classes)
				cec.EmitNewClassAdded(cls);
			//update the Relations
			foreach ( IClass cls in comp.Classes)
			{
				
				cec.EmitClassRelationsUpdated(cls.ClassName,cls);
						
			}
			
		}
		public IProject GetProject()
		{
			return new DPProject(this.DPAppDataSet);
		}
		public void SetProject( IProject proj)
		{
			try
			{
				this.autoCorrect=true;
				this.CreateNewProject(proj);
				foreach (IProjectComponent comp in proj.Components)
					foreach (IClass cls in comp.Classes)
					{
						if (cls.InheritedClasses!=null && cls.InheritedClasses.Count>0)
							foreach( IInheritance inh in cls.InheritedClasses)
								this.AddInheritance(inh,false);
						if( cls.References!=null && cls.References.Count>0)
							foreach( IReference rf in cls.References)
								this.AddReference(rf);
						if( cls.Aggregates!=null && cls.Aggregates.Count>0)
							foreach( IAggregate agg in cls.Aggregates)
								this.AddAggregate(agg);
						if( cls.Creations!=null && cls.Creations.Count>0)
							foreach( ICreation cr in cls.Creations)
								this.AddCreates(cr);
					}
			}
			catch( Exception exp)
			{
				if(!silent) ErrorMessage.Show("The following error was encountered in SetProject:"+ exp.Message+"------\n"+exp.ToString(),"Error");
				
			}
			finally
			{
				this.autoCorrect=false;
			}
		}

		public string GetTag()
		{
			MessageBox.Show(this.DPAppDataSet.DataSetName);
			return this.DPAppDataSet.DataSetName;
		}
		private void CheckAndCreate( string comp,string cname)
		{
			if( this.ContainsClass(comp,cname))
				return;
			IClass cls = new InfoClasses.ClassInfo();
			cls.ClassName=cname;
			cls.ClassType=ClassType.Concrete;
			cls.ClassSummary="Auto Generated";
			cls.ComponentName=comp;
			if( this.AddClass(cls) ) return;
				Console.WriteLine("Couldnt autogenerate class,"+ cname+" of Component:"+ comp);
		}
		public void Dispose()
		{
			this.DPAppDataSet.Dispose();
			this.eventTable.Clear();
		}
		

		#endregion
		
		private bool autouiUpdate=true;
		public bool AutoUIUpdate
		{
			get
			{
				return this.autouiUpdate;
			}
			set
			{
				this.autouiUpdate=(bool)value;
			}
		} //Tells to update the ui relations automatically or will it be done manually!
		
		private bool silent=false;
		public bool Silent
		{
			get
			{
				return this.silent;
			}
			set
			{
				this.silent=(bool)value;
			}
		}

		internal DataSet DataSet
		{
			get{ return this.DPAppDataSet;}
		}

		private void FinishMerge(object sender, EventArgs e)
		{
			//this.UpdateComponents();
		}
	}

	#region Event Handlers and Menu Handlers
	internal class ClassEventContainer
	{
		#region Events
		public event AddNewClassObserver NewClassAdded;//note this has to be used only after ReadXml() is done since the UICLass makes use of location
		public event ReInitialize ReInit;
		public event ClassNameObserver ClassNameChanged;
		public event ClassFieldObserver ClassFieldsUpdated;
		public event ClassMethodObserver ClassMethodsUpdated;
		public event RelationObserver ClassRelationsUpdated;

		#endregion

		public void EmitNewClassAdded(IClass cls)
		{
			this.NewClassAdded(cls);
		}
		public void EmitReInitialize()
		{
			
			this.ReInit(new object());//object is not used by UIComponent,
			////object is for future use
		}

		public void EmitClassFieldsUpdated(string cname,IClass cls)
		{
			this.ClassFieldsUpdated(cname,cls);
		}
		public void EmitClassMethodsUpdated(string cname,IClass cls)
		{
			this.ClassMethodsUpdated(cname,cls);
		}
		public void EmitClassRelationsUpdated(string cname, IClass cls)
		{
			
			this.ClassRelationsUpdated(cname, cls);
		}
		public void EmitClassNameUpdated(string cname, IClass cls)
		{
			this.ClassNameChanged(cname,cls);
		}
		
	}

	
	#endregion
	
}
